package Week5.J0514;

import java.util.Arrays;
import java.util.Scanner;

public class 空调遥控_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int p = scanner.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        int left = 0, right = 0, ret = 0;
        p *= 2;
        while (right < n) {
            while (arr[right] - arr[left] > p) {
                left++;
            }
            ret = Math.max(ret, right - left + 1);
            right++;
        }
        System.out.println(ret);
    }
}
